package com.syl.auth.model;

import java.io.Serializable;

/**
 * @Author YunLong
 * @Date 2023/4/27 22:37
 * @Description 统一返回结果
 **/
public class ResultVO<T> implements Serializable {

    public static final String SUCCESS_CODE = "000000";

    /**
     * 返回码
     */
    private String code;
    /**
     * 提示信息
     */
    private String msg;
    /**
     * 返回实例
     */
    private T data;

    /**
     * 有参成功
     *
     * @param result
     * @return com.ruiruan.userserver.vo.ResultVO<T>
     * @apiNote [附加描述]
     * @date 2021/3/23 15:41
     */
    public static <T> ResultVO<T> success(T result) {
        ResultVO<T> resultVO = new ResultVO<T>();
        resultVO.setCode(SUCCESS_CODE);
        resultVO.setMsg(null);
        resultVO.setData(result);
        return resultVO;
    }

    /**
     * 无参成功
     *
     * @return com.ruiruan.userserver.vo.ResultVO<T>
     * @apiNote [附加描述]
     * @date 2021/3/23 15:41
     */
    public static <T> ResultVO<T> success() {
        return success(null);
    }

    /**
     * 有参错误
     *
     * @param code 错误码
     * @param msg  错误消息
     * @return com.ruiruan.userserver.vo.ResultVO<T>
     * @apiNote [附加描述]
     * @date 2021/3/23 15:41
     */
    public static <T> ResultVO<T> error(String code, String msg) {
        ResultVO<T> resultVO = new ResultVO<>();
        resultVO.setCode(code);
        resultVO.setMsg(msg);
        return resultVO;
    }


    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "ResultVO{" +
                "code='" + code + '\'' +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
